package com.snow.springboot.task;

import com.snow.springboot.pojo.domain.DiagnoseInfo;
import com.snow.springboot.util.FileUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.List;
import java.util.concurrent.BlockingQueue;

/**
 * @Package: com.snow.springboot.task
 * @ClassName: ProductDiagnoseTask
 * @Description:生产diagnose数据，添加到队列
 * @author: lurui
 * @Date: 2018/10/26 上午10:53
 * @version:V1.0
 */
public class ProductDiagnoseTask implements Runnable {

    private static final Logger LOGGER = LoggerFactory.getLogger(ProductDiagnoseTask.class);

    private List<DiagnoseInfo> datas;

    private BlockingQueue<DiagnoseInfo> queue;

    public ProductDiagnoseTask(List<DiagnoseInfo> datas, BlockingQueue<DiagnoseInfo> queue) {
        this.datas = datas;
        this.queue = queue;
    }

    @Override
    public void run() {
        if (null != datas && datas.size() > 0) {
            for (int i = 0; i < datas.size(); i++) {
                DiagnoseInfo dataMesh = datas.get(i);
                try {
                    queue.put(dataMesh);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                    LOGGER.error("productNcms error.{}", dataMesh.getDiagnoseId());
                    FileUtil.writeByte("/Users/apple/Desktop/productId.txt", dataMesh.getDiagnoseId());
                    Thread.currentThread().interrupt();
                }
            }
        }
    }
}
